package com.hafu.view.kehu;
import com.hafu.model.KhInfo;
import com.hafu.service.KhInfoService;
import com.hafu.util.StringUtil;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;
public class AddKeHuFrm extends JFrame {
    private KhInfoService khInfoService = new KhInfoService();
    public AddKeHuFrm() {
        initComponents();
    }
    private void button1(ActionEvent e) {
        String name = textField1.getText();
        String phone = textField2.getText();
        if (StringUtil.isEmpty(name)) {
            JOptionPane.showMessageDialog(null, "客户姓名不能为空");
            return;
        }
        if (StringUtil.isEmpty(phone)) {
            JOptionPane.showMessageDialog(null, "客户电话不能为空");
            return;
        }
        KhInfo khInfo = new KhInfo(name, phone);
        Boolean aBoolean = khInfoService.addKhInfo(khInfo);
        if (aBoolean){
            JOptionPane.showMessageDialog(null,"添加成功");
            this.dispose();
        }else {
            JOptionPane.showMessageDialog(null,"添加失败");
        }
    }
    private void initComponents() {
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        textField2 = new JTextField();
        button1 = new JButton();
        setTitle("\u6dfb\u52a0\u5ba2\u6237\u8868\u5355");
        Container contentPane = getContentPane();
        label1.setText("\u5ba2\u6237\u540d\u5b57");
        label2.setText("\u5ba2\u6237\u7535\u8bdd");
        button1.setText("\u63d0\u4ea4");
        button1.addActionListener(e -> button1(e));
        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGroup(contentPaneLayout.createParallelGroup()
                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                .addGap(147, 147, 147)
                                                .addGroup(contentPaneLayout.createParallelGroup()
                                                        .addComponent(label1)
                                                        .addComponent(label2, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE))
                                                .addGap(86, 86, 86)
                                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(textField1, GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                                                        .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)))
                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                .addGap(207, 207, 207)
                                                .addComponent(button1, GroupLayout.PREFERRED_SIZE, 269, GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(265, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGap(106, 106, 106)
                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label1)
                                        .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(26, 26, 26)
                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(label2))
                                .addGap(105, 105, 105)
                                .addComponent(button1)
                                .addContainerGap(127, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
    }
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JTextField textField2;
    private JButton button1;
}
